home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  11.3 KB  |  336 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)plot_ps.c    V1.20    3/13/95";
  3. #endif
  4. /*
  5. |    file name - plot_ps.c
  6. |=======================================================================
  7. |
  8. |    This is an example program that demonstrates printing to a
  9. |    printer from within a DV-Tools program. Printing may be performed
  10. |    by any windows supported printer.
  11. |    There are three print commands:   
  12. |
  13. |       TscPrintSet   - this takes a variable argument list that allows 
  14. |                       different printer settings. See the documentation
  15. |                       for a list of possible settings. Returns an ADDRESS
  16. |                       which is passed into TscPrintStart.
  17. |       TscPrintStart - starts the print process. Accepts a SCREEN as the
  18. |                       first argument and an ADDRESS or NULL as the second
  19. |                       argument.
  20. |       TscPrintEnd   - notifies the program that printing is over. Accepts
  21. |                       a SCREEN argument.
  22. |  
  23. |     The programmer starts the the print process with TscPrintStart and
  24. |     then proceeds to draw to the printer. Between the start and end functions
  25. |     the application DC is assign to the printer. Any GDI routines used 
  26. |     will be printed to the designated printer.  
  27. |
  28. |=======================================================================
  29. */
  30.  
  31. /*
  32.  *  DV-Tools header files
  33.  */
  34. #include "std.h"                /* <stdio.h> etc., scalar & macro definitions */
  35. #include "dvstd.h"              /* public types & constants */
  36. #include "dvtools.h"            /* constants used by T routines */
  37. #include "dvGR.h"               /* constants used by window mgt & GR routines */
  38. #include "VOstd.h"              /* constants used by VO & VOob routines */
  39. #include "Tfundecl.h"           /* T routines (screens, drawports & views) */
  40. #include "VOfundecl.h"          /* VO routines (objects) */
  41. #include "VPfundecl.h"          /* VP routines (put info for dgp & vdp) */
  42. #include "VGfundecl.h"          /* VG routines (get info from dgp & vdp) */
  43. #include "VUfundecl.h"          /* VU routines (Utility) */
  44.  
  45. /* Constants */
  46. #define  DVPATH            (char *)NULL
  47. #define  DISPFORMS_STB     (char *)NULL
  48. #define  DVDEVICE          (char *)NULL
  49. #define  DVCOLORTABLE      (char *)NULL
  50. #define  VIEW_NAME         "plot.v"
  51. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  52. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  53.  
  54. /* Define & initialize view filename */
  55. char *view_name = VIEW_NAME;    /* default view name */
  56.  
  57. /* Define global variables */
  58. int slot_count, plot_file_count = 0;
  59. int draw_times = 0;
  60. float time_start, incr;
  61.  
  62. /* Functions defined in plot_ps.c */
  63.  
  64. /*
  65.  *   MAIN PROGRAM
  66.  */
  67. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  68.                      LPSTR lpCmdLine,  int nCmdShow  )
  69.  
  70. {
  71.   /*
  72.    *  program arguments
  73.    *    argv[1] - display device name (default is to use DVDEVICE)
  74.    *    argv[2] - view name (default is plot.v)
  75.    */
  76.  
  77.   /* Define & initialize device name */
  78.   char *device_name = DVDEVICE; /* default device name */
  79.  
  80.   /* Define display variables */
  81.   OBJECT   screen;         /* display device, the window */
  82.   DRAWPORT drawport;       /* how & where to display picture, picture frame */
  83.   VIEW     view;           /* picture representation of the view file */
  84.  
  85.   /* Control loop variables */
  86.   OBJECT   location;       /* the event representation */
  87.  
  88.   /* Other variables */
  89.   OBJECT    drawing,       /* graphical representation of screen */
  90.             graph_obj;     /* graph object */
  91.   DATAGROUP dgp;           /* data group pointer structure */
  92.   char     *obj_name;      /* name of objects selected */
  93.   int       Quit = NO;     /* flag to quit program */
  94.   int argc = 0;
  95.   char **argv;
  96.  
  97.  
  98.   make_argv(&argc,&argv,GetCommandLine());
  99.  
  100.   /*--------------------
  101.    *   Initialization
  102.    *
  103.    *   TInit:  perform the initialization of DV-Tools
  104.    *           TInit reads your configuration file and any
  105.    *           environment variables or logical names set.
  106.    */
  107.   TInit (DVPATH, DISPFORMS_STB);
  108.  
  109.   /*
  110.    *   TscOpenSet: open a device as a screen object using
  111.    *               specified attributes
  112.    *   TscErase:   erase the entire screen in the default
  113.    *               background color
  114.    *
  115.    *   Set exposure block to YES to insure the window
  116.    *   is ready for drawing when TdpDraw is called.
  117.    */
  118.   if (argc > 1)
  119.     device_name = argv[1];
  120.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  121.                        V_X_EXPOSURE_BLOCK, YES,
  122.                        V_ACTIVE_CURSOR, V_END_OF_LIST);
  123.   if (!screen)
  124.     {
  125.       printf ("Must specify device on command line or");
  126.       printf (" in DataViews configuration file.\n");
  127.       S_EXIT (EXIT_ERR);
  128.     }
  129.   TscErase (screen);
  130.  
  131.   /*
  132.    *   VOscWinEventMask:  sets the screen's window event mask
  133.    */
  134.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
  135.             (ULONG) 0);
  136.  
  137.   /*
  138.    *   TviLoad:   Load a view in from a file, either a
  139.    *              user supplied view or default view file plot.v
  140.    */
  141.   if (argc == 3)
  142.     view_name = argv[2];
  143.   view = TviLoad (view_name);
  144.   if (!view)
  145.     {
  146.       printf ("Could not load view from file ");
  147.       printf ("%s.\n", view_name);
  148.       S_EXIT (EXIT_ERR);
  149.     }
  150.  
  151.   /*
  152.    *   TviGetDrawing:     Gets a view's drawing object
  153.    *   TdrGetNamedObject: Gets a named object from a
  154.    *                      drawing.
  155.    *
  156.    *   Obtain the graph object from the view's drawing.
  157.    */
  158.   drawing = TviGetDrawing (view);
  159.   graph_obj = TdrGetNamedObject (drawing, "graph");
  160.  
  161.   /*
  162.    *   VOdgGetDgp: Returns pointer to the data group structure
  163.    *   VGdgslots:  Gets the number of data group slots
  164.    *   VGdgtime_start_incr:  Gets the time axis start and increment
  165.    *
  166.    *   Obtain the data group pointer which is used to retrieve
  167.    *   information about the graph such as slot count, time axis
  168.    *   start and time axis increment value.
  169.    */
  170.   dgp = VOdgGetDgp (graph_obj);
  171.   slot_count = VGdgslots (dgp);
  172.   VGdgtime_start_incr (dgp, &time_start, &incr);
  173.  
  174.   /*
  175.    *   TdpCreate: Create a DV-Tools window, a drawport.
  176.    *              The drawport is attached to the screen object
  177.    *              specified while view specifies the view to be
  178.    *              displayed on the screen.
  179.    */
  180.   drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
  181.  
  182.   /*
  183.    *   TviOpenData: Open all data source lists for this view and views
  184.    *                referenced by enabled subdrawings contained in view
  185.    *   TviReadData: Reads data from the data sources of a view
  186.    */
  187.   TviOpenData (view);
  188.   TviReadData (view);
  189.  
  190.   /*
  191.    *   TdpDraw:     Draw the contents of a drawport
  192.    */
  193.   TdpDraw (drawport);
  194.  
  195.   /*--------------------
  196.    *   Control loop
  197.    *
  198.    *   Poll the window event queue. If the user selects an object
  199.    *   named quit then exit the program. If the user selects the
  200.    *   plot button then print out the current screen display to
  201.    *   the Postscript printer. The drawport's dynamic objects
  202.    *   are updated with the current iteration of data each time
  203.    *   through the loop.
  204.    */
  205.   FOREVER
  206.   {
  207.     /*
  208.      * VOloWinEventPoll:   Poll for the next window event.
  209.      *                     The polling mode used is V_NO_WAIT.
  210.      *                     Using this mode, VOloWinEventPoll
  211.      *                     does not wait until a masked event
  212.      *                     is generated.
  213.      */
  214.     location = VOloWinEventPoll (V_NO_WAIT);
  215.     if (location)
  216.       {
  217.         /*
  218.          *  VOloType:  returns the type of event.  These types
  219.          *             match event types specified in VOscWinEventMask.
  220.          */
  221.         switch (VOloType (location))
  222.           {
  223.  
  224.           case V_RESIZE:
  225.             /*
  226.              *  The window size has been changed.
  227.              *  TscReset:  Resets all screen drawports after
  228.              *             window resizing
  229.              */
  230.             TscReset (screen);
  231.             break;
  232.  
  233.           case V_EXPOSE:
  234.             /*
  235.              *  VOloRegion:  Returns a rectangle representing the
  236.              *               exposed region on the screen.
  237.              *  TscRedraw:   After erasing, redraws all the drawports
  238.              *               in the screen.
  239.              *  A portion of the window has been exposed and needs
  240.              *  to be redrawn.
  241.              */
  242.             TscRedraw (screen, VOloRegion (location));
  243.             break;
  244.  
  245.           case V_KEYPRESS:
  246.             break;
  247.  
  248.           case V_BUTTONPRESS:
  249.             /*
  250.              *  Check button selected.
  251.              *  VOloButton:  Returns the button that was pressed
  252.              *  TloGetSelectedObjectName: Get the name of the selected object
  253.              *
  254.              *  The left mouse button acts as the selection button. If
  255.              *  the object selected by the user has a name then compare
  256.              *  this name to the exit string "quit_button". If they
  257.              *  match then exit the program.  Otherwise check to see if
  258.              *  name matches the plot button string, "plot_button". If
  259.              *  so, call the function to plot the screen.
  260.              */
  261.             switch (VOloButton (location))
  262.               {
  263.               case 1:
  264.                 obj_name = TloGetSelectedObjectName (location);
  265.                 if (obj_name)
  266.                   {
  267.                   if( strcmp( obj_name, "quit_button" ) == 0 )
  268.                     Quit = YES;
  269.                   else
  270.                     if( strcmp( obj_name, "plot_button" ) == 0 )
  271.                     {
  272.                      ADDRESS print_info;  /* Object to be passed into TscPrintStart */
  273.  
  274.           /* Set the printer attributes */
  275.                       print_info = TscPrintSet(VP_PRINT_SCALE, 50, 
  276.                                                VP_PRINT_ITER_COUNT, 10,
  277.                                                V_END_OF_LIST);
  278.          
  279.           /* Start the print process, any display calls between TscPrintStart
  280.              and TscPrintEnd will be sent to the printer */
  281.                       TscPrintStart(screen, print_info);
  282.                 
  283.           /* Call to redraw the screen, only now it goes to the printer */
  284.                       TscRedraw(screen, NULL);
  285.  
  286.           /* End the print process, all display calls after this will 
  287.              affect the display monitor */
  288.                       TscPrintEnd(screen);
  289.                      }
  290.                   }
  291.  
  292.               default:
  293.                 break;
  294.               }
  295.             break;
  296.  
  297.           default:
  298.             break;
  299.           }
  300.       }
  301.  
  302.     /* exit the program */
  303.     if (Quit == YES)
  304.       break;
  305.  
  306.     /*
  307.      *  Update the number of draw times counter
  308.      */
  309.     draw_times += 1;
  310.  
  311.     /*
  312.      *  TviReadData: Read data from the data sources of the view.
  313.      *  TdpDrawNext: Update all dynamic objects within a drawport's view
  314.      */
  315.     TviReadData (view);
  316.     TdpDrawNext (drawport);
  317.   }
  318.  
  319.   /*--------------------
  320.    *   Termination
  321.    *
  322.    *   TdpDestroy:            Destroy the drawport,
  323.    *   TviCloseData:          Close the data sources of the view
  324.    *   TviDestroy:            Destroy the view, freeing the allocated memory
  325.    *   TscClose:              Closes the screen object
  326.    *   TTerminate:            Perform the clean-up for DV-Tools
  327.    */
  328.   TdpDestroy (drawport);
  329.   TviCloseData (view);
  330.   TviDestroy (view);
  331.   TscClose (screen);
  332.   TTerminate ();
  333.   return EXIT_OK;
  334. }
  335.  
  336.